﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Text;
using Common;

public partial class common_Pager : System.Web.UI.UserControl
{

    private int curpage;
    public int CurPage
    {
        get { return curpage; }
        set { curpage = value; }
    }

    private int pagesize;
    public int PageSize
    {
        get { return pagesize; }
        set { pagesize = value; }
    }

    private int totalpage;
    public int TotalPage
    {
        get { return totalpage; }
        set { totalpage = value; }
    }

    private int recordcount;
    public int RecordCount
    {
        get { return recordcount; }
        set { recordcount = value; }
    }

    private string url;
    public string URL
    {
        get { return url; }
        set { url = value; }
    }

    private Hashtable querytable;
    public Hashtable QueryTable
    {
        get { return querytable; }
        set { querytable = value; }
    }

    private string querystring;
    public string QueryString
    {
        get { return querystring; }
        set { querystring = value; }
    }

    public void SetPageInfo(int CurPage,int RecordCount,string URL,Hashtable QueryTable)
    {
        curpage = CurPage;
        recordcount = RecordCount;
        url = URL;
        querytable = QueryTable;

        pagesize = Convert.ToInt32(ConfigurationSettings.AppSettings["PageSize"]);

        //QueryTable拼参数字符串
        string querystring = "";
        if (querytable != null)
        {
            foreach (DictionaryEntry de in querytable)
                if (de.Key.ToString() != "Type" && de.Key.ToString() != "MenuType" )
                  querystring += "&" + de.Key.ToString() + "=" + de.Value.ToString();
        }
        else
        {
            querystring = "";
        }
        QueryString = querystring;

        //总页数
        if (recordcount % PageSize == 0)
            totalpage = recordcount / PageSize;
        else
            totalpage = recordcount / PageSize + 1;

        if (totalpage > 0)
        {
            //下拉页框
            PageList.Items.Clear();
            for (int i = 0; i < totalpage; i++)
                PageList.Items.Add(new ListItem("第" + (i + 1).ToString() + "页", URL + "&curpage=" + (i + 1).ToString() + querystring));
            PageList.SelectedIndex = curpage - 1;
            PageList.Attributes.Add("onchange", "location.href=this.value"); 
        }
        else
            this.Visible = false;
        
    }

}
